#include<iostream>
#include<unistd.h>
#include<sys/ipc.h>
#include<sys/shm.h>

#define pathname "./"
#define proj_id 0x666
#define max_mem 4096

typedef int value;

//创造共享内存
int creatshm(void)
{
    key_t key = ftok(pathname, proj_id);
    int n = shmget(key, max_mem, IPC_CREAT | IPC_EXCL | 0666);
    return n;
}
//获取共享内存
int getshm(void)
{
    key_t key = ftok(pathname, proj_id);
    int n = shmget(key, max_mem, IPC_CREAT);
    return n;
}
//删除共享内存
void delshm(int shmid)
{
    shmctl(shmid, IPC_RMID, nullptr);
}